

var Loading = function (game) {
  var text;
  this.preload=function () {
    game.scale.scaleMode = Phaser.ScaleManager.SHOW_ALL;


    //game.scale.setTo(0.5);
  }
  this.create = function () {
    game.stage.backgroundColor = '#182d3b';

    game.load.image('submit', './asserts/submit.png');
    game.load.image('prev', './asserts/prev.png');
    game.load.image('next', './asserts/next.png');
    game.load.image('retry', './asserts/retry.png');




    game.load.image('opening', './asserts/opening.jpg');
    game.load.image('button', './asserts/button.png');


    game.load.image('begin', './asserts/begin.jpg');
    game.load.image('1_btn', './asserts/1_btn.png');



    game.load.image('1', './asserts/1.jpg');
    game.load.image('1_0', './asserts/1_0.jpg');
    game.load.image('1_r', './asserts/1_r.jpg');
    game.load.image('1_w', './asserts/1_w.jpg');
    game.load.image('1_10', './asserts/1_10.png');
    game.load.image('1_11', './asserts/1_11.png');
    game.load.image('1_12', './asserts/1_12.png');
    game.load.image('1_13', './asserts/1_13.png');


    game.load.image('2', './asserts/2.jpg');
    game.load.image('2_0', './asserts/2_0.jpg');
    game.load.image('2_r', './asserts/2_r.jpg');
    game.load.image('2_w', './asserts/2_w.jpg');
    game.load.image('d2_0', './asserts/d2_0.png');
    game.load.image('d2_1', './asserts/d2_1.png');
    game.load.image('d2_2', './asserts/d2_2.png');
    game.load.image('d2_3', './asserts/d2_3.png');
    game.load.image('d2_4', './asserts/d2_4.png');
    game.load.image('d2_5', './asserts/d2_5.png');
    game.load.image('d2_6', './asserts/d2_6.png');
    game.load.image('d2_7', './asserts/d2_7.png');
    game.load.image('small', './asserts/small.png');
    game.load.image('glass', './asserts/glass.png');


    game.load.image('3', './asserts/3.jpg');
    game.load.image('3_r', './asserts/3_r.jpg');
    game.load.image('3_w', './asserts/3_w.jpg');
    game.load.image('3_0', './asserts/3_0.jpg');
    game.load.image('3_00', './asserts/3_00.png');
    game.load.image('3_1', './asserts/3_1.png');
    game.load.image('3_2', './asserts/3_2.png');
    game.load.image('3_3', './asserts/3_3.png');


    game.load.image('4', './asserts/4.jpg');
    game.load.image('4_r', './asserts/4_r.jpg');
    game.load.image('4_w', './asserts/4_w.jpg');
    game.load.image('4_0', './asserts/4_0.jpg');

      game.load.spritesheet('d4_03', './asserts/d4_03.jpg', 160, 200, 20);
      game.load.spritesheet('d4_04', './asserts/d4_04.jpg', 160, 200, 20);
      game.load.image('d4_05', './asserts/d4_05.png');
      game.load.spritesheet('d4_06', './asserts/d4_06.jpg', 160, 200, 17);


    game.load.image('5', './asserts/5.jpg');
    game.load.image('5_0', './asserts/5_0.jpg');
    game.load.image('5_r', './asserts/5_r.jpg');
    game.load.image('5_w', './asserts/5_w.jpg');
    game.load.image('rect', './asserts/rect.png');
    game.load.image('rectbg', './asserts/rectbg.png');
    game.load.image('bluerect', './asserts/bluerect.png');


    game.load.image('6', './asserts/6.jpg');
    game.load.image('6_0', './asserts/6_0.jpg');
    game.load.image('6_r', './asserts/6_r.jpg');
    game.load.image('6_w', './asserts/6_w.jpg');
    game.load.image('rect', './asserts/rect.png');
    game.load.image('6add', './asserts/6add.png');


    game.load.image('7', './asserts/7.jpg');
    game.load.image('7_0', './asserts/7_0.jpg');
    game.load.image('7_r', './asserts/7_r.jpg');
    game.load.image('7_w', './asserts/7_w.jpg');
    game.load.image('l_off', './asserts/l_off.png');
    game.load.image('l_on', './asserts/l_on.png');
    game.load.image('r_off', './asserts/r_off.png');
    game.load.image('r_on', './asserts/r_on.png');





    game.load.image('final', './asserts/final.jpg');



    game.load.image('small', './asserts/small.jpg');

    game.load.start();

    game.load.onLoadStart.add(this.loadStart, this);
    game.load.onFileComplete.add(this.fileComplete, this);
    game.load.onLoadComplete.add(this.loadComplete, this);



    text = game.add.text(game.world.centerX, game.world.centerY,  'Loading ...', { fill: '#ffffff' });
    text.anchor.setTo(0.5,0.5)
  }


  this.loadStart = function () {
  }

  this.fileComplete = function (progress, cacheKey, success, totalLoaded, totalFiles) {
    var key=cacheKey.toLocaleString();
    imgs[key]=cacheKey;
    text.setText("File Complete: " + progress + "% - " + totalLoaded + " out of " + totalFiles);

  }

  this.loadComplete = function (arg) {
    game.goState('next');
  }



  this.render =function() {


    /*function resize() {
      var canvas = document.querySelector("canvas");
      console.log(canvas)

      var winW = window.screen.width;
      var winH = window.screen.height;
      var ratio = winW / winH;
      var divRation = 1624 / 750;
      var w, h, l, t = 0;
      //console.log(ratio,divRation)
      if (ratio < divRation) {
        w = winW;
        h = (winW / divRation).toFixed(0);
        t = (winH - h) / 2;
        l = 0
      } else {
        w = (winH * divRation).toFixed(0);
        h = winH;
        t = 0;
        l = (winW - w) / 2
      }*/
      /*canvas.setAttribute('width',w);
      canvas.setAttribute('height',h);
      canvas.style.width=w+'px';
      canvas.style.height=h+'px';*/

      //canvas.style.left=l+'px';
      //console.log(w, h, l, t);
      //document.getElementById('wd').innerText=w.toFixed(0) +'======'+ h.toFixed(0) +'======'+  l.toFixed(0) +'======'+  t.toFixed(0);

   /* var x = 32;
    var y = 0;
    var yi = 32;

    game.debug.text('Viewport', x, y += yi);

    game.debug.text('Viewport Width: ' + game.scale.viewportWidth, x, y += yi);
    game.debug.text('window.innerWidth: ' + window.innerWidth, x, y += yi);
    game.debug.text('window.outerWidth: ' + window.outerWidth, x, y += yi);

    game.debug.text('Viewport Height: ' + game.scale.viewportHeight, x, y += yi);
    game.debug.text('window.innerHeight: ' + window.innerHeight, x, y += yi);
    game.debug.text('window.outerHeight: ' + window.outerHeight, x, y += yi);

    game.debug.text('Document', x, y += yi*2);

    game.debug.text('Document Width: ' + game.scale.documentWidth, x, y += yi);
    game.debug.text('Document Height: ' + game.scale.documentHeight, x, y += yi);



    x = 350;
    y = 0;

    game.debug.text('Device', x, y += yi);

    game.debug.text('window.screen.width: ' + window.screen.width, x, y += yi);
    game.debug.text('window.screen.availWidth: ' + window.screen.availWidth, x, y += yi);
    game.debug.text('window.screen.height: ' + window.screen.height, x, y += yi);
    game.debug.text('window.screen.availHeight: ' + window.screen.availHeight, x, y += yi);*/

  }

}


